home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue54 / Persist / tiDBConnection.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-01-21  |  2.0 KB  |  77 lines

  1. {* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2.   (c) TechInsite Pty. Ltd.
  3.   PO Box 429, Abbotsford, Melbourne. 3067 Australia
  4.   Phone: +61 3 9419 6456
  5.   Fax:   +61 3 9419 1682
  6.   Web:   www.techinsite.com.au
  7.   EMail: peter_hinrichsen@techinsite.com.au
  8.  
  9.   Created: Jan 2000
  10.  
  11.   Notes: Wrapper a TDatabase component
  12.  
  13. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
  14. unit tiDBConnection;
  15.  
  16. interface
  17. uses
  18.   Classes
  19.   ,DB
  20.   ,DBTables
  21.   ;
  22.  
  23. type
  24.  
  25.   TtiDBConnection = class( TObject )
  26.   private
  27.     FDatabase      : TDatabase ;
  28.     FSession       : TSession ;
  29.     function GetDatabaseName: string;
  30.   public
  31.     constructor create ;
  32.     destructor  destroy ; override ;
  33.     property    DatabaseName : string read GetDatabaseName ;
  34.   end ;
  35.  
  36. implementation
  37.  
  38. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  39. // *
  40. // * TtiDBConnection
  41. // *
  42. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  43. // Create a TDatabase and TSession, then connect
  44. constructor TtiDBConnection.create;
  45. begin
  46.   inherited Create ;
  47.   FSession               := TSession.Create( nil ) ;
  48.   FSession.AutoSessionName := true ;
  49.  
  50.   FDatabase              := TDatabase.Create( nil ) ;
  51.   FDatabase.DatabaseName := 'DBMain' ;
  52.   FDatabase.DriverName   := 'INTRBASE' ;
  53.   FDatabase.LoginPrompt  := false ;
  54.   FDatabase.Params.Add( 'SERVER NAME=adrs.gdb' ) ;
  55.   FDatabase.Params.Add( 'USER NAME=SYSDBA'     ) ;
  56.   FDatabase.Params.Add( 'PASSWORD=masterkey'   ) ;
  57.   FDatabase.SessionName := FSession.Name ;
  58.   FDatabase.Connected    := true ;
  59. end;
  60.  
  61. // Destroy the database and session
  62. //------------------------------------------------------------------------------
  63. destructor TtiDBConnection.destroy;
  64. begin
  65.   FSession.Free ;
  66.   FDatabase.Free ;
  67.   inherited;
  68. end;
  69.  
  70. // Return the database's name for connection to TQuery(s)
  71. function TtiDBConnection.GetDatabaseName: string;
  72. begin
  73.   result := FDatabase.DatabaseName ;
  74. end;
  75.  
  76. end.
  77.